package com.spancer.contentcenter.service;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * author by: mars
 * Date: 2020/10/8 16:12
 * Description:
 * SpringBoot源码解析（ Chapter-3）
 * > 获取上下文的工具类
 */
@Component
public class SpTestService implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    // 获取上下问中的环境变量
    public String test(){
        return applicationContext.getEnvironment().getProperty("key3");
    }
}
